<template>
	<view class="container">
		<view class="user_header">
			<!-- 未登录状态 -->
			<navigator url="/pages/login/index" class="goToLogin" v-if="!isLogin">去登录</navigator>
			<!-- 已登录状态 -->
			<view class="logo" v-else>
				<image class="icon" :src="avatarUrl || '/static/empty.png'"></image>
				<view class="name">{{nickName}}</view>
			</view>
			<image v-show="isLogin" :src="avatarUrl || '/static/empty.png'" class="bg"></image>
		</view>
		<!-- 订单导航 -->
		<view class="order_nav">
			<view class="nav" @click="goToOrderList(1)">
				<view class="iconfont icon-icon-test"></view>
				<view class="name">待付款</view>
			</view>
			<view class="nav" @click="goToOrderList(2)">
				<view class="iconfont icon-daishouhuo"></view>
				<view class="name">待收货</view>
			</view>
			<view class="nav" @click="goToOrderList(0)">
				<view class="iconfont icon-tuihuo"></view>
				<view class="name">退货/退款</view>
			</view>
			<view class="nav" @click="goToOrderList(0)">
				<view class="iconfont icon-quanbudingdan01"></view>
				<view class="name">全部订单</view>
			</view>
		</view>
		<!-- 应用信息 -->
		<view class="app_info">
			<view class="info" @click="callPhone">
				<view class="iconfont icon-kefu"></view>
				<view class="name">联系客服</view>
				<view class="value">400-618-4000</view>
			</view>
			<view class="info" @click="goToFeedBack">
				<view class="iconfont icon-fankuitianbao"></view>
				<view class="name">意见反馈</view>
				<view class="value"></view>
			</view>
			<!-- 如果是小程序平台，显示版本号，如果是web平台，不显示版本 -->
			<!-- #ifdef MP-WEIXIN -->
				<view class="info">
					<view class="iconfont icon-banben"></view>
					<view class="name">当前版本</view>
					<view class="value">v4.1.1</view>
				</view>
			<!-- #endif -->
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				nickName: '',
				avatarUrl: '', // 头像
				isLogin: false // 用户是否登录
			};
		},
		onShow() {
			this.checkLogin();
		},
		methods: {
			checkLogin() {
				// 通过Token判断是否已经登录
				const token = uni.getStorageSync('token');
				if (token) {
					// 已经登录
					const userInfo = uni.getStorageSync('userInfo');
					console.log(userInfo)
					this.nickName = userInfo.nickName;
					this.avatarUrl = userInfo.avatarUrl;
					this.isLogin = true;
				} else {
					// 未登录
					this.isLogin = false;
				}
			},
			// 跳转到订单列表
			goToOrderList(orderType) {
				uni.navigateTo({
					url: '/pages/order/index?orderType=' + orderType
				})
			},
			// 拨打客服电话
			callPhone() {
				uni.makePhoneCall({
					phoneNumber: '400-666-888'
				})
			},
			goToFeedBack() {
				uni.navigateTo({
					url: '/pageA/feedback/index'
				})
			}
		}

	}
</script>


<style lang="less">
	.container {
		background-color: #FAFAFA;
		.user_header {
			height: 329rpx;
			display: flex;
			justify-content: center;
			align-items: center;
			position: relative;
			.bg {
				filter: blur(20rpx);
				position: absolute;
				left: 0;
				right: 0;
				top:0;
				bottom: 0;
				width: 100%;
				height: 100%;
			}
			.logo {
				display: flex;
				flex-direction: column;
				align-items: center;
				z-index: 1;
				.icon {
					width: 172rpx;
					height: 172rpx;
					border-radius: 100%;
				}
				.name {
					color: #fff;
					font-size: 32rpx;
					font-weight: bold;
					margin-top: 16rpx;
				}
			}
			.goToLogin {
				display: flex;
				justify-content: center;
				align-items: center;
				color: #fff;
				font-size: 36rpx;
				background-color: #07C160;
				border-radius: 8rpx;
				width: 352rpx;
				height: 88rpx;
			}
		}
		.order_nav {
			display: flex;
			margin: 0 12rpx;
			border-radius: 8rpx;
			background-color: #fff;
			justify-content: space-around;
			.nav {
				display: flex;
				flex-direction: column;
				align-items: center;
				padding: 14rpx 0;
				.iconfont {
					font-size: 60rpx;
				}
				.name {
					font-size: 26rpx;
				}
			}
		}
		.app_info {
			background-color: #fff;
			margin: 20rpx 12rpx;
			font-size: 26rpx;
			color: #434343;
			.iconfont {
				font-size: 45rpx;
			}
			.info {
				display: flex;
				justify-content: space-between;
				height: 101rpx;
				align-items: center;
				padding: 0 40rpx;
				border-bottom: 1px solid #C8C8C8;
				.name {
					margin-left: 28rpx;
				}
				.value {
					flex: 1;
					text-align: right;
				}
			}
		}
	}
</style>

